﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Csharpzuoye
{
    public class Unit
    {
        public static int GetMax(int[] arrays) //声明方法
        {
            int max = arrays[0];

            for (int i = 0; i < arrays.Length; i++)
            {
                if (arrays[i] > max)
                {
                    max = arrays[i];
                    continue;
                }
            }
            return max;
        }

        //找到100以内的所有质数 
        //拆分为找到100以内质数的个数，判断这个数是不是质数两个步骤去完成
        public static void GetPrime()
        {
            for (int i = 2; i < 100; i++)
            {
                if (IsPrime(i))
                {
                    Console.WriteLine(i);
                }
            }
        }

        public static bool IsPrime(int number)
        {
            for (int i = 2; i < number; i++)
            {
                if (number % i == 0 && i != number)
                {
                    return false;
                }
            }
            return true;


        }
        public static int BinarySeek(int[] numbers)
        {

            int target = 45;
            int left = 0,
            right = numbers.Length - 1,
            middle;
            while (left < right)
            {
                middle = (left + right) / 2;
                if (target < numbers[middle])
                {
                    right = middle - 1;
                }
                else if (target > numbers[middle])
                {
                    left = middle + 1;
                }
                else //if(target == numbers[middle])
                {

                    return numbers[middle];
                }
            }
            return -1;
        }

       
        private int[] arrays;
        private int top = 0;
        public Unit(int length)
        {
            arrays = new int[length];
        }
        public bool Push(int element)
        {
            if (top > arrays.Length)
            {
                Console.WriteLine("stack overflow");
                return false;
            }
            else
            {
                arrays[top] = element;
                top++;
                return true;
            }
        }
        public bool Pop()
        {
            if (top == 0)
            {
                Console.WriteLine("The stack is empty");
                return false;
            }
            else
            {
                top--;
                Console.WriteLine(arrays[top]);
                return true;
            }

        }
    }
}

